package com.unknowpupil.web.service.impl;

import com.unknowpupil.web.base.BaseCrudService;
import com.unknowpupil.web.base.impl.BaseCrudServiceImpl;
import com.unknowpupil.web.domain.Transaction;
import com.unknowpupil.web.service.IAccountInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.unknowpupil.web.mapper.TransactionMapper;
import com.unknowpupil.web.service.ITransactionService;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * @Classname: ${NAME}
 * @Author: <a> w10g </a>
 * @CreateDate: Create in 2019/11/6 14:55
 * @Description:
 * @Version: 1.0
 */
@Service
public class TransactionServiceImpl extends BaseCrudServiceImpl<Transaction,TransactionMapper> implements ITransactionService {

    @Resource
    private TransactionMapper transactionMapper;

    @Autowired
    private IAccountInfoService accountinfoService;

    @Override
    public Transaction createTransaction(String send, String get, String tx, Long block, double balance, String currency, BigInteger nonce){
        String sendUser = accountinfoService.findUserNameByAddress(send);
        String getUser = accountinfoService.findUserNameByAddress(get);
        BigDecimal amount = new BigDecimal(balance);
        Transaction transaction = new Transaction();
        transaction.setSend(send);
        transaction.setGet(get);
        transaction.setNonce(nonce.intValue());
        transaction.setTxnHash(tx);
        transaction.setBlock(block);
        transaction.setSendBalance(amount);
        transaction.setSendUser(sendUser);
        transaction.setGetUser(getUser);
        transaction.setCurrency(currency);
        transaction.setGetBalance(amount);
        transaction.setDelFlag(0);
        transaction.setStatus(0);
        transaction.setRemark("Third party transfer");
        return transaction;

    }

}
